<?php
/**
 * Created by PhpStorm.
 * 商品分类模型
 * User: caicm
 * Date: 2017/6/17
 * Time: 15:01
 */

namespace WMApi\Model;


use Think\Model;

class WmCategoryModel extends Model {

    /**
     * 获取分类列表
     * Created By caicm
     * @param int $parent_id
     * @return mixed
     */
    public function get_category_list($parent_id=0){

        $where = array(
            'is_show' => 1,
            'is_del' => 0,
            'parent_id' => $parent_id
        );

        $field = 'cat_id,cat_name,parent_id,level';

        return $this->field($field)->where($where)->order('sort desc,cat_id desc')->select();

    }


    /**
     * 获取父级分类id
     * Created By caicm
     * @param $cat_id
     * @return mixed
     */
    public function get_parent_id($cat_id){

        $where = array(
            'is_show' => 1,
            'is_del' => 0,
            'cat_id' => $cat_id
        );

        return $this->where($where)->getField('parent_id');

    }

}